package com.aruio.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * @className: ResourceWebSocketConfig
 * @author: zhanyurui
 * @date: 2024/11/16 星期六 11:21
 * @Version: 1.0
 * @description: 资源监控websocket类
 */
@Configuration
@EnableWebSocketMessageBroker
public class ResourceWebSocketConfig implements WebSocketMessageBrokerConfigurer {

	// 添加服务端点，接受客户端连接
	@Override
	public void registerStompEndpoints(StompEndpointRegistry registry) {
		// 添加一个断点并允许开启SockJS支持
		registry.addEndpoint("/websocket").setAllowedOrigins("*").withSockJS();
	}

	// 设置消息连接请求的各种规范信息
	@Override
	public void configureMessageBroker(MessageBrokerRegistry registry) {
		// 客户端接收服务端消息的地址的前缀信息
		registry.enableSimpleBroker("/resource");
		// 服务端接收地址的前缀
		registry.setApplicationDestinationPrefixes("/app");
	}
}
